<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var arr = [
        { id: '29', pid: '', name: '总裁办' },
        { id: '2c', pid: '', name: '财务部' },
        { id: '2d', pid: '2c', name: '财务核算部' },
        { id: '2f', pid: '2c', name: '薪资管理部' },
        { id: 'd2', pid: '', name: '技术部' },
        { id: 'd3', pid: 'd2', name: 'Java研发部' },
        { id: 'd31', pid: 'd3', name: 'Java研发部333' },
        { id: 'd33', pid: 'd3', name: 'Java研发部333' },
      ];

      // 递归 --- 函数内部自己调用自己
      // 斐波那契数列  1 1 2 3 5 8 13 21 。。。
      // 递归： 函数内部自己调用自己 +  函数内部一定要有退出条件
      function loop(n) {
        if (n === 1 || n === 2) {
          return 1;
        }
        return loop(n - 1) + loop(n - 2);
      }

      console.log(loop(5)); // 5
      console.log(loop(7)); // 13
      console.log(loop(20)); // 13
    </script>
  </body>
</html>
